const dynamicComponentsContext = require.context('./', true, /\.vue$/)

export interface ComponentsInterface {
  [key: string]: any
}

const components: ComponentsInterface = {}

dynamicComponentsContext.keys().forEach((key: string) => {
  const componentContext = dynamicComponentsContext(key)
  const component = componentContext.default
  if (component.options && component.options.name) {
    components[component.options.name] = component
  }
})

const componentNames: string[] = Object.keys(components)

export {
  components,
  componentNames,
}
